﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using Isha.Data;
using Isha.Data.Infrastructure;
using Isha.Entities;
using Isha.Repositories;
using Isha.Services;

namespace Isha.Framework.Web
{
    internal class IshaDatabaseInitializer : DropCreateDatabaseIfModelChanges<IshaDbContext>
    {

        protected override void Seed(IshaDbContext context)
        {
            //IDatabaseFactory db = new DatabaseFactory();
            //IUnitOfWork unitofwork = new UnitOfWork(db);
            //ILanguageService languageService = new LanguageService(new LanguageRepository(db), unitofwork);
            //IContentTypeService contenttypeService = new ContentTypeService(new ContentTypeRepository(db), unitofwork);
            //IContentItemService contentService = new ContentItemService(new ContentItemRepository(db), unitofwork);
            //ISecurityService securityService = new SecurityService(new UserRepository(db), new RoleRepository(db), unitofwork);
            //IPartService partService = new PartService(new PartRepository(db), unitofwork);
            //AccountMembershipService membership = new AccountMembershipService();

            //languageService.CreateLanguage(new Language()
            //                                   {
            //                                       Title = "English"
            //                                   }
            //                               );

            //int languageId = languageService.GetLanguage(1).LanguageID;

            //securityService.CreateRole(new Role()
            //                               {
            //                                   RoleName = "admin"
            //                               }
            //                          );

            //securityService.CreateRole(new Role()
            //                                {
            //                                    RoleName = "contributor"
            //                                }
            //                          );

            //membership.CreateUser("admin", "admin01", "admin@isha.com");
            //membership.CreateUser("content", "content01", "content@isha.com");

            //securityService.AssignRole("admin", new List<string>() { "admin" });
            //securityService.AssignRole("content", new List<string>() { "contributor" });

            //contenttypeService.CreateContentType(new ContentType()
            //                                        {
            //                                            Title = "Isha",
            //                                            IsPublic = false
            //                                        }
            //                                     );

            //contenttypeService.CreateContentType(new ContentType()
            //                                         {
            //                                             Title = "Folder",
            //                                             IsPublic = true
            //                                         }
            //                                     );

            //contenttypeService.CreateContentType(new ContentType()
            //                                        {
            //                                            Title = "Page",
            //                                            IsPublic = true
            //                                        }
            //                                    );

            //contenttypeService.CreateContentType(new ContentType()
            //                                         {
            //                                             Title = "File",
            //                                             IsPublic = true
            //                                         }
            //                                    );

            //contenttypeService.CreateContentType(new ContentType()
            //                                        {
            //                                            Title = "Link",
            //                                            IsPublic = true
            //                                        }
            //                                   );

            //partService.CreatePart(new Part()
            //                            {
            //                                Name = "shared__branding",
            //                                Html = "<h1>Isha</h1>"
            //                            }
            //                      );

            //contentService.CreateContentItem(new ContentItem()
            //                                     {
            //                                         Title = "Isha",
            //                                         Description = "This is Root Folder",
            //                                         ContentTypeID = contenttypeService.GetContentType("Folder").ContentTypeID,
            //                                         IsPublished = true,
            //                                         LanguageID = languageId,
            //                                         ExcludeNavigation = false,
            //                                         AllowComments = false,
            //                                         DisplayOrder = 1,
            //                                         CreatedBy = "admin",
            //                                         CreatedOn = DateTime.Now
            //                                     }
            //                                 );

            //contentService.CreateContentItem(new ContentItem()
            //{
            //    Title = "Welcome to the Isha Demo site!",
            //    Link = "front-page",
            //    Description = "",
            //    ContentTypeID = contenttypeService.GetContentType("Page").ContentTypeID,
            //    LanguageID = languageId,
            //    IsPublished = true,
            //    ExcludeNavigation = false,
            //    AllowComments = false,
            //    ParentItemID = 1,
            //    DisplayOrder = 1,
            //    ContentXml = IshaContext.Current.Serializer(typeof(Page),new Page()
            //              {
            //                  BodyText = "<p><span>Isha is a powerful and flexible, enterprise-quality content management system that is easy for developers to download and install, and easy for end-users to use. Isha lets non-technical people create and maintain website content using only a web browser. Isha offers a rich set of capabilities for public websites, private intranets and collaborative workspaces.</span></p><p>This demo site will allow you to experience the overall look and feel of Isha and its easy-to-use functions and features.  This site has some customization to give you an idea of Isha's  possibilities while remaining close to the default out of the box Isha site. If you are new to Isha, you probably will want to first <a href=account\\logon>log in as an admin</a> and start with your own <a class=guided-tour><b>Guided Tour</b></a></p><p>You may simply log in using any of the options below to learn how each permission works.</p>"
            //                          + "<p>NOTE: <b>The data in this site will be wiped out every night at 3:00 AM US Eastern</b>. No emails will be sent from this site so that it cannot be abused by spammers. Please keep in mind that many users may be connected at the same time and make changes to the site that can conflict with yours.</p>"
            //                          + "<h2>Demo Accounts</h2>"
            //                          + "<p>There are three demo accounts set up for you to use. These accounts allow you to"
            //                          + " <a href=account\\logon>log in</a> "
            //                          + "as a user to get the full Isha experience.  One of the features of Isha that elevates it as an enterprise-level Content  Management System is internal security. Below, you will see three  logins.  This allows the administrators to determine which users can add  content, which users can publish content and who has administrator  rights. This helps keep the tone and style of your content consistent as  needed.</p>"
            //                          + "<h4>Content Contributor</h4>"
            //                          + "<p>A content contributor can add content and submit it for review.</p>"
            //                          + "<p class=callout><b>Username: </b>content<br /> <b>Password:</b> content01</p>"
            //                          + "<h4>Site Administrator</h4>"
            //                          + "<p>A site administrator has super user powers. All features will be available for this user.</p>"
            //                          + "<p class=callout><b>Username:</b> admin<br /> <b>Password:</b> admin01</p>"
            //                          + "<h2>Once You Are Logged In</h2>"
            //                          + "<p>Once you have logged in, you can add content, publish content and modify the site's settings. We encourage you to try each of the logins so that you can understand the internal controls that are offered for your organization. If you have never used Isha before, or wish to learn more about its features, we have put together"
            //                          + "a series of tutorials in our <a class=guided-tour href=><b>Guided Tour</b></a></p>"
            //                          + "<h2>To Learn More</h2>"
            //                          + "<p>Our goal for this demo is to give you a solid understanding of the basic functionalities offered by Isha so that you can imagine "
            //                          + "how it wouldd apply to your organization. If you have any further questions, please contact <a>Six Feet Up</a>."
            //              }),
            //    CreatedBy = "admin",
            //    CreatedOn = DateTime.Now
            //}
            //                                 );

            //contentService.CreateContentItem(new ContentItem()
            //                                     {
            //                                         Title = "SiteConfig",
            //                                         Description = "SiteConfig",
            //                                         ContentTypeID = contenttypeService.GetContentType("Isha").ContentTypeID,
            //                                         ExcludeNavigation = true,
            //                                         ContentXml = IshaContext.Current.Serializer(typeof(IshaConfig),
            //                                                      new IshaConfig()
            //                                                      {
            //                                                          SiteName = "Isha",
            //                                                          LanguageID = languageId,
            //                                                          Home = 2
            //                                                      }),
            //                                         CreatedBy = "admin",
            //                                         CreatedOn = DateTime.Now
            //                                     }
            //                                 );

            //contentService.CreateContentItem(
            //                          new ContentItem()
            //                          {
            //                              Title = "This page does not seem to exist…",
            //                              Link = "404",
            //                              Description = "",
            //                              ContentTypeID = contenttypeService.GetContentType("Page").ContentTypeID,
            //                              LanguageID = languageId,
            //                              IsPublished = true,
            //                              ExcludeNavigation = true,
            //                              AllowComments = false,
            //                              ParentItemID = 1,
            //                              DisplayOrder = 3,
            //                              ContentXml =  IshaContext.Current.Serializer(typeof(Page),new Page()
            //                                        {
            //                                            BodyText = "<div id=content-core><p>We apologize for the inconvenience, but the page you were trying to access is not at this address. You can use the links below to help you find what you are looking for.</p><ul><li>Review the address to make sure it is correct: <strong>http://Isha-demo.Isha.com/dsad</strong></li><li><a href=/search>Search the site</a> for the page you were trying to access, as it may have moved </li><li>If you are certain you have the correct web address but are encountering an error, please contact the <span><a href=/contact-info>Site Administration</a></span>. </li><li>View the <a href=/sitemap>Site map</a> </li><li>Go to the <a href=>home page</a> </li></ul></div>"
            //                                        }),
            //                              CreatedBy = "admin",
            //                              CreatedOn = DateTime.Now
            //                          }
            //                      );


            //contentService.CreateContentItem(
            //                            new ContentItem()
            //                            {
            //                                Title = "Sample Content",
            //                                Description = "<p><span>At the left, you will see folders with articles that relate to a specific area of interest. We have used articles from Wikihow that you may use in the Six Feet Up Plone demo. You may use these articles to browse content, move it or edit it. It will help you better understand how visitors to your website would experience the content that you publish.</span></p>",
            //                                ContentTypeID = contenttypeService.GetContentType("Folder").ContentTypeID,
            //                                LanguageID = languageId,
            //                                IsPublished = true,
            //                                ExcludeNavigation = false,
            //                                AllowComments = false,
            //                                ParentItemID = 1,
            //                                DisplayOrder = 2,
            //                                CreatedBy = "admin",
            //                                CreatedOn = DateTime.Now
            //                            }
            //                        );


            //contentService.CreateContentItem(
            //                            new ContentItem()
            //                            {
            //                                Title = "Guided Tour",
            //                                Description = "<p><span>Isha is a powerful and flexible, enterprise-quality content management system that is easy for developers to download and install, and easy for end-users to use. Isha lets non-technical people create and maintain website content using only a web browser. Isha offers a rich set of capabilities for public websites, private intranets and collaborative workspaces.</span></p>",
            //                                ContentTypeID = contenttypeService.GetContentType("Folder").ContentTypeID,
            //                                LanguageID = languageId,
            //                                IsPublished = true,
            //                                ExcludeNavigation = false,
            //                                AllowComments = false,
            //                                ParentItemID = 1,
            //                                DisplayOrder = 2,
            //                                CreatedBy = "admin",
            //                                CreatedOn = DateTime.Now
            //                            }
            //                        );

            //contentService.CreateContentItem(
            //                           new ContentItem()
            //                           {
            //                               Title = "Google",
            //                               Description = "<p><span>Isha is a powerful and flexible, enterprise-quality content management system that is easy for developers to download and install, and easy for end-users to use. Isha lets non-technical people create and maintain website content using only a web browser. Isha offers a rich set of capabilities for public websites, private intranets and collaborative workspaces.</span></p>",
            //                               ContentTypeID = contenttypeService.GetContentType("Link").ContentTypeID,
            //                               LanguageID = languageId,
            //                               IsPublished = true,
            //                               ExcludeNavigation = false,
            //                               AllowComments = false,
            //                               ParentItemID = 6,
            //                               DisplayOrder = 4,
            //                               ContentXml = IshaContext.Current.Serializer(typeof(Link), new Link()
            //                                         {
            //                                             ExternalLink = "http://www.google.com"
            //                                         }),
            //                               CreatedBy = "admin",
            //                               CreatedOn = DateTime.Now
            //                           }
            //                       );

            //contentService.CreateContentItem(
            //                           new ContentItem()
            //                           {
            //                               Title = "About Isha",
            //                               Description = "",
            //                               ContentTypeID = contenttypeService.GetContentType("Page").ContentTypeID,
            //                               LanguageID = languageId,
            //                               IsPublished = true,
            //                               ExcludeNavigation = false,
            //                               AllowComments = false,
            //                               ParentItemID = 1,
            //                               DisplayOrder = 3,
            //                               ContentXml = IshaContext.Current.Serializer(typeof(Page), new Page()
            //                                         {
            //                                             BodyText = "<h3>What is a Content Management System?</h3><p>A Content Management System (CMS) allows users to create, manage and publish content to a website without requiring a high level of technical skill. </p><p>As websites have grown larger and more complex, content management systems like Plone have grown in popularity, since they provide an efficient, easy way for people to create and edit content in a consistent, secure and controllable fashion.  CMSes also enable website visitors to interact with content and with each other by contributing comments, ratings, submitting forms and more.</p><p>Using a CMS is critical to the success and long term maintainability of almost any website or intranet.</p>"
            //                                         }),
            //                               CreatedBy = "admin",
            //                               CreatedOn = DateTime.Now
            //                           }
            //                       );


            //contentService.CreateContentItem(
            //                          new ContentItem()
            //                          {
            //                              Title = "Parenting",
            //                              Description = "<p><span>Items in the Parenting folder address issuessuch as work/life balance, raising respectful children and managing changes within the family such as parents returning to work, divorce and death</span></p>",
            //                              ContentTypeID = contenttypeService.GetContentType("Folder").ContentTypeID,
            //                              LanguageID = languageId,
            //                              IsPublished = true,
            //                              ExcludeNavigation = false,
            //                              AllowComments = false,
            //                              ParentItemID = 5,
            //                              DisplayOrder = 2,
            //                              CreatedBy = "admin",
            //                              CreatedOn = DateTime.Now
            //                          }
            //                      );

            //contentService.CreateContentItem(
            //                        new ContentItem()
            //                        {
            //                            Title = "Parenting",
            //                            Description = "<p><span>Items in the Parenting folder address issuessuch as work/life balance, raising respectful children and managing changes within the family such as parents returning to work, divorce and death</span></p>",
            //                            ContentTypeID = contenttypeService.GetContentType("Folder").ContentTypeID,
            //                            LanguageID = languageId,
            //                            IsPublished = true,
            //                            ExcludeNavigation = false,
            //                            AllowComments = false,
            //                            ParentItemID = 6,
            //                            DisplayOrder = 2,
            //                            CreatedBy = "admin",
            //                            CreatedOn = DateTime.Now
            //                        }
            //                    );

            base.Seed(context);
        }
    }
}

